Which of the four hardware layers everything this instance draws sits on, against BACKGROUNDS - 0 is closest to the viewer, 3 is furthest back, and 3 is the default. Separate from `depth`, which orders sprites against each other within one layer.
Works differently on Game Boy - bg_priority works on one background layer with one picture number for the room: a sprite is in front of the picture when its number is the picture's or lower, behind its shades 1 to 3 when higher, and overlapping sprites go by X, the lower X in front.
Works differently on Game Boy Color - bg_priority works on one background layer with one picture number for the whole room: a sprite is in front of the picture when its number is the picture's or lower, behind its colors 1 to 3 when higher, and of two sprites the lower is in front.
On other consoles this differs: see Side by side and How the consoles differ.
bg_priority: intWhich of the GBA's four hardware layers everything this instance draws in world space sits on, measured against backgrounds. 0 is closest to the viewer, 3 is furthest back, and 3 is the default.
The rule the hardware applies: a sprite draws in front of a background when its bg_priority is less than or equal to that background's own priority, and behind it otherwise.
It belongs to the instance, not to any one drawing call - but only for world-space drawing. Setting it moves everything this instance draws in the world - its own sprite, and every draw_sprite and draw_text call it makes - onto that layer together. Anything outside 0..3 is clamped rather than refused, so a stray value is never an error.
Anything drawn in a Draw GUI event does NOT read this field at all (nor does an _anchored call). Screen-fixed content always draws on its own front-most layer, whatever bg_priority this instance happens to have - see the "GUI content is always in front" section below.
bg_priority = 1;In an object's Create event: this instance's own world-space sprite (and any draw_sprite/draw_text it makes) now sits one layer in front of the default - useful when it needs to clear something else in the world, such as a background made with background_create. This has no effect at all on anything the same instance draws in its Draw GUI event, or with an _anchored call - those always draw in front regardless.
Everything drawn in a Draw GUI Begin, Draw GUI or Draw GUI End event - and everything drawn with an _anchored call - is on the screen layer: it is stuck to the screen, and it sits on top of the whole game. It draws on its own front-most hardware layer automatically - the same layer a shrouded room's own shroud claims, so it clears the shroud too, with nothing to set. And among the sprites on that layer it sorts in a band of its own, in front of every sprite the world can make - even one you lifted to bg_priority 0 and gave a very low depth. This is deliberate: "GUI" and the Draw GUI End event both promise content that sits on top of everything, so the engine keeps that promise by default rather than asking every project to discover the right bg_priority value by hand.
This holds for a script too: a script called from a Draw GUI event draws on the screen layer, and the same script called from a Draw event draws in the world.
Want one GUI element behind another - a HUD panel behind its own label, say? Set a higher depth on the one that should sit further back (never a different bg_priority - see "Not the same knob as depth" below). Every GUI draw already shares this one front layer, so depth is what decides which wins inside it, exactly like any other same-layer pair in this engine.
There is deliberately no way to make GUI content sit BEHIND the world - that is what the world-space draw_sprite/draw_text calls in a Draw event (plus this field) are for instead.
(This section is about world-space drawing only - the sprite an instance shows by default, plus draw_sprite/draw_text in a Draw event. Draw GUI content is covered above and never needs any of this.)
Floors go to the back. A room's own layers claim priorities starting from the back: 0 is the shroud if the room is shrouded (still front-most), and its tile layers count backwards from the hardware's own back-most value. A room's first tile layer - normally its only one, since the room editor authors at most one today - lands on that back-most value itself, the same value bg_priority already defaults to.
So an ordinary object, left completely untouched, ties with an ordinary room's floor - and on real GBA hardware a tie always goes to the sprite, never the background (in the Game Boy Advance module's own words: "sprites cover backgrounds of the same priority"). An instance that never sets bg_priority at all already stands in front of the floor it is standing on, no per-object change needed.
This used to be the opposite, and it is worth knowing the shape of the old failure even though it can no longer happen by default: a room's floor used to claim the front-most tile-layer priority (1), and a default instance (3) was > 1, so it sat behind its own floor - completely invisible, with nothing logging a warning or failing to compile, just on the wrong side of a background. If old notes, an old build, or a room with more than one tile layer still describe "clear the floor by raising bg_priority," that is what they mean, and the second case - more than one layer - can still need it: see the table below.
| What it draws | Does it need a bg_priority change? |
|---|---|
| Anything in the world at the default (3), in a room with exactly one tile layer (or none) - the player, enemies, pickups, props | No. It already ties with the floor and wins. |
| A HUD, a menu, dialogue, a screen fade - anything meant to sit over the world | No, as long as it draws in a Draw GUI event (or with an _anchored call) - that already clears even a shrouded room's shroud, automatically (see above). |
| Something that has to look screen-fixed but is drawn in a Draw event from world positions - rare, and generally not what you want | Yes, it still needs bg_priority set to clear an ordinary background - but even at 0 it still CANNOT clear a shrouded room's own shroud, and a world sprite can still draw over it (the shroud and the screen layer are the only things that sit above the world). Move that drawing into a Draw GUI event instead of reassembling the effect by hand. |
| A second or third tile layer, painted deliberately in FRONT of default-priority instances - a bridge rail, a tree canopy the player should walk under | Not from GBML today. A room's own tile layers stack automatically (each later one a step further towards the front than the one before it), and hand-written C++ room code can retarget a specific layer's own background directly (room_find_background + background_priority, gbml/room.h/gbml/background.h) - but neither of those two functions is wired up as a GBML call yet, and the room editor itself authors at most one tile layer per room today anyway, so this is a real, disclosed gap rather than a live option, not something to reach for. |
| Something deliberately drawn BEHIND a one-layer room's own floor - a pit, a grate seen through a gap | Not with bg_priority alone, and not from GBML today either: the floor already sits on the hardware's own back-most value, so nothing can be assigned a value further back than it, and moving the floor itself off that slot needs the same not-yet-GBML-exposed room_find_background/background_priority pairing as the row above. |
An object that draws nothing in world space - no sprite, no draw call in a Draw event - has nothing for this field to order, so leaving it at the default costs nothing either way, even if the same instance also draws GUI content (which ignores this field entirely).
depthbg_priority and depth answer two different questions, and neither can answer the other's.
bg_priority orders this instance's world-space drawing against backgrounds. It is a two-bit hardware field: four values, nothing in between, and no sort key hidden inside it. Draw GUI content never reads it (see above).depth orders this instance against other sprites, and only ever within the same bg_priority - world-space or GUI alike (the screen layer is the one exception: it sorts in front of every world sprite, whatever their depth). Two instances on different priorities ignore each other's depth completely.A world-space backdrop that has to sit in front of the room's floor but behind its own world-space text needs both: the same bg_priority on the backdrop and the text, so they are on one layer at all, and then a higher depth on the backdrop so the text wins inside that layer. A GUI backdrop (draw_rect_fill in a Draw GUI event) and its own GUI text (draw_text in the same event) need none of that - both already share the one front layer automatically, so only depth is left to set, exactly the same way.
background_priority is the same number read from the other side - it sets the layer a background you made with background_create draws on, and a background you show with draw_background keeps that layer (without the call, it takes the drawing object's bg_priority, moved forward by the order of the calls). The same comparison decides the outcome for WORLD-space drawing, so a backdrop at priority 1 and a world-space label at bg_priority 0 puts the label in front; equal numbers put the sprite in front too. A draw_text label in a Draw GUI event needs no bg_priority at all here either - it already draws in front of any background, this one included, automatically.
A sprite draws IN FRONT of a background when its bg_priority is less than or equal to that background's own priority, and behind it otherwise - EQUAL counts as in front too (in the words of the GBA module: "sprites cover backgrounds of the same priority"), so a tie always favours the instance. The current room already claims some layers: 0 is its shroud if it is a shrouded room, and its own tile layers count backwards from the back-most value - a room's first tile layer (its floor, and normally its only one, since the room editor authors at most one per room today) sits AT that back-most value itself, the same one bg_priority already defaults to. So an instance that never touches this field already draws in front of an ordinary one-layer room's floor, tying with it and winning - no per-object change needed for that common case any more. What still needs bg_priority 0 is anything that also has to clear a SHROUD (a HUD, a menu) - a shrouded room's dark overlay keeps the front-most layer to itself, in front of a default instance. A room authored with more than one tile layer stacks the later ones one step towards the front of the first, automatically, with no authoring choice attached to any one layer yet - giving one specific layer its own explicit priority (to make it a deliberate foreground layer, or to move a floor aside) is not possible yet. Anything outside 0..3 is clamped, never an error. Values are a hardware field, not a sort key: two instances on the same layer are ordered by `depth` alone.